//
//  BarTableCell.m
//  HappyTravel
//
//  Created by JiePan’s Mac on 2018/8/7.
//  Copyright © 2018年 Apple. All rights reserved.
//

#import "BarTableCell.h"
#import "NSString+HTSize.h"

@implementation BarTableCell

#pragma mark - init
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if ([super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self initSubViews];
    }
    return self;
}

- (void)initSubViews {
    [self.contentView addSubview:self.imagePortrait];
    [self.contentView addSubview:self.lineView];
    [self.contentView addSubview:self.dateLabel];
    [self.contentView addSubview:self.deleteBtn];
    [self.contentView addSubview:self.backView];
    [self.backView addSubview:self.contentLabel];
//    [self.backView addSubview:self.photoImage];
    [self.backView addSubview:self.listImageView];

    [self.imagePortrait mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self).offset(15);
        make.top.mas_equalTo(self).offset(0);
        make.width.height.mas_equalTo(18);
    }];
    
    [self.lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.imagePortrait.mas_bottom);
        make.bottom.mas_equalTo(self).offset(0);
        make.width.mas_equalTo(2);
        make.centerX.mas_equalTo(self.imagePortrait.mas_centerX);
    }];
    
    [self.dateLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.imagePortrait.mas_right).offset(15);
        make.centerY.mas_equalTo(self.imagePortrait.mas_centerY);
    }];
    
    [self.deleteBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(self).offset(-30);
        make.centerY.mas_equalTo(self.imagePortrait.mas_centerY);
    }];
    
    [self.backView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(self).offset(-30);
        make.left.mas_equalTo(self.dateLabel.mas_left);
        make.top.mas_equalTo(self.dateLabel.mas_bottom).offset(20);
        make.bottom.mas_equalTo(self).offset(-20);
    }];
    
    [self.contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(self.backView.mas_right).offset(-15);
        make.left.mas_equalTo(self.backView.mas_left).offset(15);
        make.top.mas_equalTo(self.backView.mas_top).offset(10);
    }];
    
    [self.listImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(self.backView.mas_right).offset(-15);
        make.left.mas_equalTo(self.backView.mas_left).offset(15);
        make.top.mas_equalTo(self.contentLabel.mas_bottom).offset(15);
        make.bottom.mas_equalTo(self.backView.mas_bottom).offset(-20);
//        make.height.mas_equalTo(140);
    }];
    
}

#pragma mark - touches events
- (void)leftBtnArray:(UIButton *)button {
    
    if (self.didClickDeleteBlock) {
        self.didClickDeleteBlock(button);
    }
}

#pragma mark - getter
- (UIImageView *)imagePortrait {
    if (!_imagePortrait) {
        _imagePortrait = [[UIImageView alloc] init];
        _imagePortrait.image = [UIImage imageNamed:@"ateDefineAll"];
    }
    return _imagePortrait;
}

- (UIView *)lineView {
    if (!_lineView) {
        _lineView = [[UIView alloc] init];
        _lineView.backgroundColor = UIColorOfHex(0x333333);
    }
    return _lineView;
}

- (UILabel *)dateLabel {
    if (!_dateLabel) {
        _dateLabel = [[UILabel alloc] init];
        _dateLabel.text = @"2018-07-09";
        _dateLabel.textColor = UIColorOfHex(0x333333);
        _dateLabel.backgroundColor = [UIColor clearColor];
        _dateLabel.font = [UIFont systemFontOfSize:16];
    }
    return _dateLabel;
}

- (UIButton *)deleteBtn {
    if (!_deleteBtn) {
        _deleteBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_deleteBtn setBackgroundImage:[UIImage imageNamed:@"flowDelete"] forState:UIControlStateNormal];
        [_deleteBtn addTarget:self action:@selector(leftBtnArray:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _deleteBtn;
}

- (UIView *)backView {
    if (!_backView) {
        _backView = [[UIView alloc]init];
        _backView.backgroundColor = [UIColor whiteColor];
        _backView.layer.cornerRadius = 10;
        _backView.layer.shadowColor = [UIColor lightGrayColor].CGColor;
        _backView.layer.shadowOffset = CGSizeZero;
        _backView.layer.shadowOpacity = 0.5;
    }
    return _backView;
}

- (UILabel *)contentLabel {
    if (!_contentLabel) {
        _contentLabel = [[UILabel alloc] init];
        _contentLabel.text = @"Have a good time tonight. I must come again next time.";
        _contentLabel.numberOfLines = 0;
        _contentLabel.font = [UIFont systemFontOfSize:15];
        _contentLabel.backgroundColor = [UIColor clearColor];
    }
    return _contentLabel;
}

- (HeaderView *)listImageView {
    if (!_listImageView) {
        _listImageView = [[HeaderView alloc] init];
    }
    return _listImageView;
}

//- (UIImageView *)photoImage {
//    if (!_photoImage) {
//        _photoImage = [[UIImageView alloc]init];
//        _photoImage.image = [UIImage imageNamed:@""];
//        _photoImage.layer.cornerRadius = 12;
//        _photoImage.layer.masksToBounds = YES;
//    }
//    return _photoImage;
//}

- (void)awakeFromNib {
    [super awakeFromNib];
    
}

- (void)setModel:(HTModel *)model {
    _model = model;
    
    self.dateLabel.text = model.currentTime;
    self.contentLabel.text = model.content;
    self.listImageView.model = model;
    
    CGSize size = [model.content stringSizeWithContentSize:CGSizeMake([[UIScreen mainScreen] bounds].size.width-90, MAXFLOAT) font:[UIFont systemFontOfSize:15]];
    _model.rowHeight = ceil(size.height) + self.listImageView.height + 111;
}

- (CGFloat)setupUI:(HTModel *)model {
    CGSize size = [model.content stringSizeWithContentSize:CGSizeMake([[UIScreen mainScreen] bounds].size.width-90, MAXFLOAT) font:[UIFont systemFontOfSize:15]];
    self.listImageView.model = model;
    return ceil(size.height) + self.listImageView.height + 111;
}

#pragma mark - touches events
- (void)getHasBeenCity{
    
//    if (self.didClickDeleteBlock) {
//        self.didClickDeleteBlock();
//    }
}






@end
